package com.tianjipms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianjipms.dao.ParkingMapper;
import com.tianjipms.dao.VehicleMapper;
import com.tianjipms.entity.Parking;
import com.tianjipms.entity.ParkingCount;
import com.tianjipms.service.ParkingService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class ParkingServiceImpl extends ServiceImpl<ParkingMapper, Parking> implements ParkingService {
    @Resource
    private VehicleMapper vehicleMapper;
    @Resource
    private ParkingMapper parkingMapper;
    @Override
    public ParkingCount findParkingData(Integer parkingAll) {
        ParkingCount parkingCount = new ParkingCount();
        //普通车位
        Integer isVipParkingCount = parkingAll - vehicleMapper.countByIsVip(1);
        parkingCount.setIsVipParkingCount(isVipParkingCount);
        //内部车位
        parkingCount.setVipParkingCount(vehicleMapper.countByIsVip(1));
        //内部车位对外出租
        Integer isUseVipParkingCount = vehicleMapper.countIsUserByVip();
        parkingCount.setIsUseVipParkingCount(vehicleMapper.countIsUserByVip());
        //剩余车位
        Integer parking = isUseVipParkingCount + isVipParkingCount;
        parkingCount.setSurplusParking(parking - parkingMapper.countByisVip(0));
        return parkingCount;
    }


}
